package com.computer.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.computer.datebase.DateBase;
import com.computer.product.Computer;



@WebServlet("/addcomputer")
public class AddComputerServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Object obj = request.getAttribute("computers");
		response.setContentType("text/html;charset=utf-8");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		
		out.print("<html><body><table border='1'>");
		if(obj != null) {
			Set<Computer> list = (Set<Computer>)obj;
			for(Computer p : list) {
				out.print("<tr>");
				out.print("<td>" + p.getBrand() + "</td>");
				out.print("<td>" + p.getColor() + "</td>");
				out.print("<td>" + p.getPrice() + "</td>");
				out.print("<td><a href='cart?brand=" + p.getBrand() + "'>添加购物车</a></td>");
				out.print("</tr>");
			}
		}
		
		out.print("</table><a href='showcomputer'>查看购物车</a></body></html>");
		out.flush();
		out.close();
	
	}
	
	
}









